<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<!DOCTYPE html>
<html lang="zh-CN">
<head>

  <%@ include file="/WEB-INF/include/meta.jsp"%>
  <%@ include file="/WEB-INF/include/css.jsp"%>
  
</head>

<body>

  <%@ include  file="/WEB-INF/include/header.jsp"%>
  
  <%@ include file="/WEB-INF/include/menu.jsp"%>
  
  <div class="container main-content">
  
    <div class="panel panel-default x-panel x-panel-layout">
    
      <div class="panel-heading">
        <ol class="breadcrumb">
          <li><a href="${ctx.host}/user">用户管理</a></li>
          <li class="active">满意度调查</li>
        </ol>
      </div>
    
      <div class="panel-body">
      
        <div class="col-xs-2 x-panel-layout-left no-horizontal-padding">
          <%@ include file="/WEB-INF/include/submenu.jsp"%>
        </div>
      
        <div class="col-xs-10 x-panel-layout-right">
          <div class="x-breadcrumb-wrapper">
            <div class="x-breadcrumb clearfix">
              <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>满意度调查&nbsp;-&nbsp;完成情况</span></h2>
              <div class="pull-right">
                <c:choose>
                  <c:when test="${not empty currentPrincipal.site}">
                    <span class="current-branchCode">${currentPrincipal.site.name}</span>
                  </c:when>
                  <c:otherwise>
                    <select name="siteId" class="select2">
                      <option value="">所有门店</option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${site.id == siteId ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </div>
            </div>
          </div>
          
          <div class="x-toolbar-wrapper top-margin-20 clearfix">
            <div class="btn-group pull-left">
              <a href="${ctx.host}/satisfaction-surveys?siteId=${siteId}" class="btn btn-${empty complete ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${empty complete ? 'success' : 'default'}">全部</a>
              <a href="${ctx.host}/satisfaction-surveys?siteId=${siteId}&complete=true" class="btn btn-${complete ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${complete ? 'success' : 'default'}">已完成</a>
              <a href="${ctx.host}/satisfaction-surveys?siteId=${siteId}&complete=false" class="btn btn-${(not empty complete and !complete) ? 'success' : 'default'} x-btn btn-shadow btn-shadow-${(not empty complete and !complete) ? 'success' : 'default'}">未完成</a>
            </div>
            
            <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
              <div class="btn-group pull-right">
                <a href="${ctx.host}/satisfaction-surveys/export-view" data-target="#export" data-toggle="modal" class="btn btn-default x-btn btn-shadow btn-shadow-default">
                  <i class="glyphicon glyphicon-floppy-save"></i>&nbsp;&nbsp;导出
                </a>
              </div>
            </c:if>
          </div>
          
          <table class="table table-striped table-hover x-table bottom-margin-20">
            <thead>
              <tr>
                <th>姓名</th>
                <th>手机号</th>
                <th>门店</th>
                <th>主教练</th>
                <th>发送时间</th>
                <c:if test="${empty complete or complete}">
                  <th>完成时间</th>
                  <c:if test="${currentPrincipal.root or currentPrincipal.admin}"><th class="text-center">操作</th></c:if>
                </c:if>
              </tr>
            </thead>
            <tbody>
              <c:choose>
                <c:when test="${empty surveys}">
                  <tr>
                    <c:choose>
                      <c:when test="${not empty complete and !complete}"><td class="text-center" colspan="5">暂无符合要求的结果</td></c:when>
                      <c:otherwise>
                        <td class="text-center" colspan="${(currentPrincipal.root or currentPrincipal.admin) ? 7 : 6}">暂无符合要求的结果</td>
                      </c:otherwise>
                    </c:choose>
                  </tr>
                </c:when>
                <c:otherwise>
                  <c:forEach var="survey" items="${surveys}">
	                <tr>
	                  <td>${survey.courseRound.student.name}</td>
	                  <td>${survey.courseRound.student.mobile}</td>
	                  <td>${survey.courseRound.site.name}</td>
	                  <td>${survey.courseRound.coach.name}</td>
	                  <td><fmt:formatDate value="${survey.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
	                  <c:if test="${empty complete or complete}">
	                    <td><fmt:formatDate value="${survey.fillInTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
	                    <c:if test="${currentPrincipal.root or currentPrincipal.admin}">
	                      <td class="text-center">
	                        <c:if test="${not empty survey.fillInTime}"><a href="${ctx.host}/satisfaction-surveys/${survey.id}" title="详情">详情</a>&nbsp;&nbsp;</c:if>
	                      </td>
	                    </c:if>
	                  </c:if>
	                </tr>
	              </c:forEach>
                </c:otherwise>
              </c:choose>
            </tbody>
          </table>
          
          <div class="form-horizontal clearfix">
            
            <jsp:include page="/WEB-INF/include/page.jsp">
              <jsp:param name="url" value="satisfaction-surveys" />
              <jsp:param name="queryString" value="${queryString}" />
            </jsp:include>
            
          </div>
          
        </div>
      </div>
    </div>
  </div>
  
  <%@ include file="/WEB-INF/include/script.jsp"%>
  <d:resource root="${ctx.resource}/build" type="script" src="js/page/market/satisfaction-survey-list.js">
    <script type="text/javascript">
      require(['page/market/satisfaction-survey-list'], function(page) {
        page.init({
          complete: '${complete}'
        })
      })
    </script>
  </d:resource>
  
</body>
</html>